package com.xayy.scheduled.controller;


import cn.kawins.base.result.CheckResult;
import cn.kawins.base.result.ResultBody;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xalan.internal.lib.NodeInfo;
import com.xayy.mgt.model.NodeTreeInfo;
import com.xayy.mgt.service.NodeInfoService;
import com.xayy.scheduled.model.vo.AssessTaskInfoVo2;
import com.xayy.scheduled.service.AssessTaskInfoService;
import com.xayy.scheduled.model.AssessTaskInfo;
import com.xayy.scheduled.model.dto.AssessTaskInfoDto;
import com.xayy.scheduled.model.vo.AssessTaskInfoVo;
import com.xayy.scheduled.convert.AssessTaskInfoConvert;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import javax.validation.Valid;
import java.util.List;

import java.io.Serializable;
import java.util.List;

/**
*  controller
*
* @ClassName: AssessTaskInfoController
* @Description: 控制层访问接口
* @author zhoutanxin
* @date 2025-06-24
*/
@Api(tags="评估任务表接口管理")
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1.0/assessTaskInfo")
public class AssessTaskInfoController  {
    private final  AssessTaskInfoService assessTaskInfoService;
    @Autowired
    NodeInfoService nodeInfoService;

    @PostMapping({"/page"})
    @ApiOperation(value = "分页")
    public ResultBody page(@RequestBody AssessTaskInfoDto query){
        PageInfo<AssessTaskInfoVo> page = assessTaskInfoService.page(query);

        return ResultBody.success(page);
    }

    @GetMapping({"/list"})
    @ApiOperation(value = "获取列表")
    public ResultBody list(AssessTaskInfoDto query){
        List<AssessTaskInfoVo> list=assessTaskInfoService.listByDTO(query);

        return ResultBody.success(list);
    }

    @GetMapping("{id}")
    @ApiOperation(value = "获取信息")
    public ResultBody get(@PathVariable("id") Long id){
        AssessTaskInfo entity = assessTaskInfoService.selectById(id);

        return ResultBody.success(AssessTaskInfoConvert.INSTANCE.convert(entity));
    }

    @PostMapping({"/save"})
    @ApiOperation(value = "保存")
    public ResultBody save(@RequestBody AssessTaskInfoVo2 vo){
        assessTaskInfoService.save(vo);
        return ResultBody.success();
    }

    @PutMapping({"/update"})
    @ApiOperation(value = "修改")
    public ResultBody update(@RequestBody AssessTaskInfoVo vo){
        AssessTaskInfo entity = assessTaskInfoService.update(vo);
        return (entity != null) ? ResultBody.success(entity) : ResultBody.failed("更新失败");
    }

    @DeleteMapping({"/delete"})
    @ApiOperation(value = "删除")
    public ResultBody delete(@RequestBody List<Long> idList){
        assessTaskInfoService.delete(idList);

        return ResultBody.success();
    }

    @GetMapping("/toggleStartPause/{id}")
    @ApiOperation(value = "启动/暂停任务")
    public ResultBody toggleStartPause(@PathVariable("id") String idstr){
        Long id =  Long.parseLong(idstr);
        assessTaskInfoService.toggleStartPause(id);

        return ResultBody.success();
    }
}